package main

func main() {

}

// 运算子 Functor
func add(a, b int) int {
	return a + b
}
func sub(a, b int) int {
	return a - b
}

var operators map[string]func(a, b int) int

func init() {
	operators = map[string]func(a, b int) int{
		"+": add,
		"-": sub,
	}
}

func calculator(a, b int, op string) int {
	if fn, ok := operators[op]; op != "" && fn != nil {
		return fn(a, b)
	}
	return 0
}
